// LogCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "NSRefDataTool.h"
#include "LogCtrl.h"


// LogCtrl

IMPLEMENT_DYNAMIC(LogCtrl, CListCtrl)

LogCtrl::LogCtrl()
{
}

LogCtrl::~LogCtrl()
{
}


BEGIN_MESSAGE_MAP(LogCtrl, CListCtrl)
	ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, &OnCustomdraw)
END_MESSAGE_MAP()



// LogCtrl message handlers



void LogCtrl::OnCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
{
	NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);

	*pResult = 0;

	if (CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage)
	{
		*pResult = CDRF_NOTIFYITEMDRAW;
	}
	else if (CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage)
	{
		*pResult = CDRF_DODEFAULT;

		COLORREF crText;
		COLORREF crTextBk;

		wchar_t text[11] = {0,};
		GetItemText(pLVCD->nmcd.dwItemSpec, 0, text, 11);

		std::wstring type(text);

		switch (type.find(L" "))
		{
		case 6: // info
			return;
		case 9: // warning
			crText = RGB(255, 255, 255);
			crTextBk = RGB(0, 0, 255);
			break;
		case 7: // error
			crText = RGB(255, 255, 255);
			crTextBk = RGB(255, 0, 0);
			break;
		}

		pLVCD->clrText = crText;
		pLVCD->clrTextBk = crTextBk;
	}
}